<?php 
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
	session_start(); 
}

$nofullsize=0;
if(isset($_REQUEST['nofullsize']))
	$nofullsize=1;
if(isset($_REQUEST['xacnhan'])){
	//echo 'aaa';
	$mang1=$_SESSION['listCategory'];
	foreach ($mang1 as $value => $giatri){
		$giatri[6]=str_replace(",","",$giatri[6]);
		$kq = mysql_query("SELECT * from category c where c.id =".$giatri[0]);
		if(mysql_num_rows($kq)>=1)
			mysql_query("UPDATE `category` SET `name`='$giatri[1]', `dateStart`='$giatri[2]', `regular`='$giatri[3]',`isDelete`='$giatri[4]', `method`='$giatri[5]',`payment`='$giatri[6]' WHERE (`id`='$giatri[0]')");
		else
			mysql_query("INSERT INTO `category` (`id`,`name`, `dateStart`, `regular`, `isDelete`, `method`, `payment`) VALUES ('$giatri[0]','$giatri[1]', '$giatri[2]', '$giatri[3]', '$giatri[4]', '$giatri[5]', '$giatri[6]')");
	}
	
	$idCategory=$_REQUEST['idCategory'];
	$nameCategory=$_REQUEST['nameCategory'];
	$dateStart=$_REQUEST['dateStart'];
	$regular=$_REQUEST['regular'];
	$method=$_REQUEST['method'];
	$payment=$_REQUEST['payment'];
	
	for($i=0;$i<count($idCategory);$i++){
		$payment[$i]=str_replace(",","",$payment[$i]);
		$kq = mysql_query("SELECT * from category c where c.id =".$idCategory[$i]);
		if(mysql_num_rows($kq)>=1)
			mysql_query("UPDATE `category` SET `name`='$nameCategory[$i]', `dateStart`='$dateStart[$i]', `regular`='$regular[$i]', `method`='$method[$i]', `payment`='$payment[$i]' WHERE (`id`='$idCategory[$i]')");
		else
			mysql_query("INSERT INTO `category` (`name`, `dateStart`, `regular`, `method`, `payment`) VALUES ('$nameCategory[$i]', '$dateStart[$i]', '$regular[$i]','$method[$i]','$payment[$i]')");
	}
}



$vyear=date("Y");
//unset($_SESSION['months1']);
//unset($_SESSION['years1']);

if (!isset($_SESSION['months1']))
	$_SESSION['months1']=date("m");
if (!isset($_SESSION['years1']))
	$_SESSION['years1']=date("Y");

if(isset($_REQUEST['months'])){
	$_SESSION['months1']=$_REQUEST['months'];
}
if(isset($_REQUEST['years'])){
	$_SESSION['years1']=$_REQUEST['years'];
}


if(isset($_REQUEST['prev'])){
		$m=$_REQUEST['months']-1;
		if($m<1){
			$_SESSION['months1']=12;
			$_SESSION['years1']=$_REQUEST['years']-1;
		}else $_SESSION['months1']=$_REQUEST['months']-1;
}

if(isset($_REQUEST['next'])){
		$m=$_REQUEST['months']+1;
		if($m>12){
		$_SESSION['months1']=1;
		$_SESSION['years1']=$_REQUEST['years']+1;
		}else $_SESSION['months1']=$_REQUEST['months']+1;
}


define('ADAY',(60*60*24));
$datearray = getdate();
$month = intval($_SESSION['months1']);
//$month=4;
$year = intval($_SESSION['years1']);
//$year=2012;
$mday=$datearray['mday'];
//$mday=21;
$start= mktime(0,0,0,$month,1,$year);
$firstdayarray = getdate($start);

$nmonth=date('m');
if($lang=='EN'){
$months = Array('January','February','March','April','May','June','July','August','September','October','November','December');
$days = Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
}
if($lang=='VN'){
$months = Array('Tháng Một','Tháng Hai','Tháng Ba','Tháng Tư','Tháng Năm','Tháng Sáu','Tháng Bảy','Tháng Tám','Tháng Chín','Tháng Mười','Tháng Mười Một','Tháng Mười Hai');
$days = Array('Chủ Nhật','Thứ Hai','Thứ Ba','Thứ Tư','Thứ Năm','Thứ Sáu','Thứ Bảy');
}
if($lang=='KR'){
$months = Array('1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월');
$days = Array('일','월','화','수','목','금','토');
}

$mang=array();
$mang2=array();
//$sqlLogMoney=mysql_query("SELECT l.*,c.`name`,c.`isDelete` FROM LogMoney l, category c WHERE MONTH(l.datetime)=$month AND YEAR(l.datetime)=$year  AND l.idcategory=c.id");
//echo "SELECT l.*,c.`name`,c.`isDelete` FROM LogMoney l, category c WHERE MONTH(l.datetime)=$month AND YEAR(l.datetime)=$year  AND l.idcategory=c.id";
//while ($row = mysql_fetch_array($sqlLogMoney)){
///$mang[]=array($row['idcategory'],$row['name'],$row['datetime'],number_format($row['money']),$row['status'],$row['isDelete']);
//}
$sqlCategory=mysql_query("SELECT * FROM category c WHERE c.isDelete=0 ORDER BY DAY(c.dateStart)");

$mang1=array();

//echo $month.'-'.$year;

while ($row = mysql_fetch_array($sqlCategory)){
	
	$d=$row['dateStart'];
	$r=$row['regular'];
	$i=0;


	$mang1[]=array($row['id'],$row['name'],$d,$r,$row['isDelete'],$row['method'],$row['payment']);
	//echo strtotime($d)."-".strtotime($year.'-'.$month.'-'.date("d")).'<br>';
	//if($row['isDelete']==0){
	//if(strtotime($d)<strtotime($year.'-'.$month.'-'.date("d")))
	//if( intval(date('m',strtotime($d))) <= intval($month) && intval(date('Y',strtotime($d))) <= intval($year) )
	//echo $d;
	//$date=date("".intval($year)."-".intval($month)."-01");
	while ($i>-1){
			//if( intval(date('m',strtotime($d." +".($r*$i)." month"))) > intval($month) && intval(date('Y',strtotime($d." +".($r*$i)." month"))) > intval($year) ){
			//	$i=-3;
			//}
			//echo $d;
			//echo intval(date('m',strtotime($d." +".($r*$i)." month"))).'-'.intval(date('Y',strtotime($d." +".($r*$i)." month"))).'     ';
			if( intval(date('m',strtotime($d." +".($r*$i)." month"))) == intval($month) && intval(date('Y',strtotime($d." +".($r*$i)." month"))) == intval($year) ){
				$d0=strtotime($d." +".($r*$i)." month");
	 			$d1= date("Y-m-d",$d0);
	 	
	 			$d10= date("m",$d0);
	 			$d11= date("Y",$d0);
	 			$kq=mysql_query("SELECT l.money,l.status,l.note,l.method FROM LogMoney l WHERE l.idcategory=".$row['id']." AND MONTH(l.datetime)='$d10' AND YEAR(l.datetime)='$d11'");
	 			
	 			//echo "SELECT l.money,l.status,l.note FROM LogMoney l WHERE l.idcategory=".$row['id']." AND MONTH(l.datetime)='$d10' AND YEAR(l.datetime)='$d11';"."<br>";
	 			$money="";
	 			$status=0;
	 			if(mysql_num_rows($kq)>0){
		 			while ($row1=mysql_fetch_array($kq)){
		 				$money=number_format($row1['money']);
		 				$status=$row1['status'];
		 				$method=$row1['method'];
		 				$note=$row1['note'];
		 				$mang[]=array($row['id'],$row['name'],$d1,$money,$status,$method,$note);
		 			}
	 			
	 			}else{
	 				
	 				$mang[]=array($row['id'],$row['name'],$d1,$row['payment'],0,$row['method'],"");
	 				$a=split('-',$d1);
	 				$kq = mysql_query("SELECT * from LogMoney l where l.idcategory =".$row['id']." AND MONTH(l.datetime)='".$a[1]."' AND YEAR(l.datetime)='".$a[0]."'");
					if(mysql_num_rows($kq)<1)
						mysql_query("INSERT INTO `LogMoney` (`idcategory`, `datetime`, `money`,`status`,`method`,`note`) VALUES ('".$row['id']."', '".$d1."', '".$row['payment']."', '0','".$row['method']."','')");
	 			}
	 			$i=-3;
	 			
			}
			if(intval(date('Y',strtotime($d." +".($r*$i)." month"))) > intval($year)){
				$i=-3;
			}
			
		//}
		//if( strtotime($d." +".($r*$i)." month")>strtotime($date)){
		//	$i=-3;
		//}
		$i++;
		
	}
	//echo  "<br>";
	
}

foreach ($mang as $value => $giatri){
	
	$kq=mysql_query("SELECT l.*,c.`name` FROM LogMoney l , category c WHERE l.idcategory=c.id AND l.idcategory=".$giatri[0]." AND l.datetime=(
SELECT l.datetime - INTERVAL c.regular MONTH FROM LogMoney l , category c WHERE l.idcategory=c.id AND l.idcategory=".$giatri[0]." AND MONTH(l.datetime)=".$month." AND YEAR(l.datetime)=".$year." ORDER BY l.datetime DESC LIMIT 0,1
)");
	while ($row1=mysql_fetch_array($kq)){
		
		//if (intval(date('m',strtotime($row1['datetime']))) < intval($month))
		$mang2[]=array($row1['id'],$row1['name'],$row1['datetime'],number_format($row1['money']),$row1['status'],$row1['note']);
 	}
 
 			
}
/*$mang3=array();
foreach ($mang as $value => $giatri){
	if($giatri[5]==0)
		$mang3[]=$giatri;
}

$mang=$mang3;*/
$_SESSION['inputMoneys']=$mang;
$_SESSION['listCategory']=$mang1;

$queryDepartment = mysql_query("SELECT d.IDDepartment,dl.DepartmentName FROM department d,department_lang dl WHERE d.IDDepartment=dl.IDDepartment AND dl.LangID='$lang';");
$querySendMail = mysql_query("SELECT e.IDEmployee,e.FullName FROM list_sendmailpay l,employee e WHERE  e.IDEmployee=l.employee_id GROUP BY l.employee_id");

include 'popup/popup_loadCategory.php';
include 'popup/popup_inputMoney.php';
include 'popup/popup_sendmailPay.php';
?>
<script type="text/javascript">
window.onload = function(){
	for(var i=1;i<=<?=count($mang1)?>;i++){
		new JsDatePick({
			useMode:2,
			target:"dateStart"+i,
			dateFormat:"%Y-%m-%d"
		});
	}
};
$(document).ready(function(){
	for(var i=1;i<=<?=count($mang)?>;i++){
		$('#money'+i).priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
	}

	for(var i=1;i<=<?=count($mang1)?>;i++){
		$('#payment'+i).priceFormat({
			prefix: '',
			centsLimit: 0,
			centsSeparator: '',
			thousandsSeparator: ','
		});
	}
});

function UpdateMoney(){
	
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											   window.location.assign("pay.php?months=<?=$month?>&years=<?=$year?>");
										  }
									  }
	xmlhttp.open("GET","content_pay/UpdateMoney.php",true);
	
	xmlhttp.send();

}
function UpdateCategory(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											  window.location.assign("pay.php");
										  }
									  }
	xmlhttp.open("GET","content_pay/UpdateCategory.php",true);
	
	xmlhttp.send();

}
function LoadCategory(){

		if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
		}else{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlhttp.onreadystatechange=function(){
											  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											    	document.getElementById("Category").innerHTML=xmlhttp.responseText;
											    	var countmang1=document.getElementById("countmang1").value;
											    	//alert(countmang1);
											    	for(var i=1;i<=countmang1;i++){
											    		new JsDatePick({
											    			useMode:2,
											    			target:"dateStart"+i,
											    			dateFormat:"%Y-%m-%d"
											    		});
											    		$('#payment'+i).priceFormat({
											    			prefix: '',
											    			centsLimit: 0,
											    			centsSeparator: '',
											    			thousandsSeparator: ','
											    		});
											    	}
											    		
											  }
										  }
		xmlhttp.open("GET","content_pay/LoadCategory.php",true);
		xmlhttp.send();
}

function LoadinputMoney(month,year){
	//alert('may vao day nha');
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("inputMoney").innerHTML=xmlhttp.responseText;
										    	
										    	for(var i=1;i<=<?=count($mang)?>;i++){
										    		$('#money'+i).priceFormat({
										    			prefix: '',
										    			centsLimit: 0,
										    			centsSeparator: '',
										    			thousandsSeparator: ','
										    		});
										    	}
										    	
										  }
									  }
	xmlhttp.open("GET","content_pay/LoadinputMoney.php?month="+month+"&year="+year,true);
	
	xmlhttp.send();

}
function delCategory(idCategory){

	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											  
										    	document.getElementById("Category").innerHTML=xmlhttp.responseText;
										    	var countmang1=document.getElementById("countmang1").value;
										    	for(var i=1;i<=countmang1;i++){
										    		new JsDatePick({
										    			useMode:2,
										    			target:"dateStart"+i,
										    			dateFormat:"%Y-%m-%d"
										    		});
										    		$('#payment'+i).priceFormat({
										    			prefix: '',
										    			centsLimit: 0,
										    			centsSeparator: '',
										    			thousandsSeparator: ','
										    		});
										    	}
										  }
									  }
	xmlhttp.open("GET","content_pay/delCategory.php?idCategory="+idCategory,true);
	
	xmlhttp.send();

}
function addCategory(){

	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											  
										    	document.getElementById("Category").innerHTML=xmlhttp.responseText;
										    	var countmang1=document.getElementById("countmang1").value;
										    	//alert(countmang1);
										    	for(var i=1;i<=countmang1;i++){
										    		new JsDatePick({
										    			useMode:2,
										    			target:"dateStart"+i,
										    			dateFormat:"%Y-%m-%d"
										    		});
										    		$('#payment'+i).priceFormat({
										    			prefix: '',
										    			centsLimit: 0,
										    			centsSeparator: '',
										    			thousandsSeparator: ','
										    		});
										    	}
										  }
									  }
	xmlhttp.open("GET","content_pay/addCategory.php",true);
	
	xmlhttp.send();

}
function chnameCategory(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chnameCategory.php?nameCategory="+encodeURIComponent(str)+"&id="+id,true);
	
	xmlhttp.send();
}
function chdateStart(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chdateStart.php?dateStart="+str+"&id="+id,true);
	xmlhttp.send();
}
function chregular(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chregular.php?regular="+str+"&id="+id,true);
	
	xmlhttp.send();
}
function chmethod(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chmethod.php?method="+str+"&id="+id,true);
	
	xmlhttp.send();
}
function chpayment(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chpayment.php?payment="+str+"&id="+id,true);
	
	xmlhttp.send();
}
function chMoney(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chMoney.php?money="+str+"&id="+id,true);
	xmlhttp.send();
}
function chmethod1(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chmethod1.php?method="+str+"&id="+id,true);
	
	xmlhttp.send();
}
function chNote(str,id){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										  }
									  }
	xmlhttp.open("GET","content_pay/chNote.php?note="+str+"&id="+id,true);
	xmlhttp.send();
}
function chActive(id,status){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
											  document.getElementById("inputMoney").innerHTML=xmlhttp.responseText;
											  for(var i=1;i<=<?=count($mang)?>;i++){
										    		$('#money'+i).priceFormat({
										    			prefix: '',
										    			centsLimit: 0,
										    			centsSeparator: '',
										    			thousandsSeparator: ','
										    		});
										    	}
										  }
									  }
	xmlhttp.open("GET","content_pay/chActive.php?id="+id+"&status="+status,true);
	xmlhttp.send();
}
function showsendmailPay(){
    $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
    $('#fade').css({'filter' : 'alpha(opacity=60)'}).fadeIn(); //Fade in the fade layer       


    popup_window_show('#sample9', { pos : 'window-center', width : '600px', height:'800px'});
									

}
function showUser1(str){
    if (str==""){
        document.getElementById("txtHint").innerHTML="";
        return;
    } 
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
            onLoad();
        }
    }
    xmlhttp.open("GET","ajax/getuser1.php?q="+str,true);
    xmlhttp.send();
}
function showReference1(str){ 
    if (str==""){
        document.getElementById("txtHint1").innerHTML="";
        return;
    } 
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
            onLoad();
        }
    }
    xmlhttp.open("GET","ajax/getreference3.php?idemployee="+str,true);
    xmlhttp.send();
}
function rmReference1(str){ 
    if (str==""){
        document.getElementById("txtHint1").innerHTML="";
        return;
    } 
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
            onLoad();
        }
    }
    xmlhttp.open("GET","ajax/rmreference3.php?idemployee="+str,true);
    xmlhttp.send();
}
function sendmail(){
    if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }else{// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if (xmlhttp.readyState==4 && xmlhttp.status==200){
            //document.getElementById('showview').setAttribute('style','opacity:1; position:relative;');
            alert("Update Send mail successful");
            onLoad();
        }
    }
    xmlhttp.open("GET","content_pay/sendmail.php",true);

    xmlhttp.send();
}

function showpay(co){
    if(co==1){
    	document.getElementById('showpay1').setAttribute('style','display:none;padding-top:10px;');
    	document.getElementById('showpay2').setAttribute('style','display:block;padding-top:10px;');
    }
    if(co==2){
    	document.getElementById('showpay2').setAttribute('style','display:none;padding-top:10px;');
    	document.getElementById('showpay1').setAttribute('style','display:block;padding-top:10px;');
    }
}
</script>
<style>
<!--
* {padding:0; margin:0;}
-->
</style>

	<style type="text/css">
      div.item { padding-top: 5px;}
    </style>
    <link rel="stylesheet" href="content_pay/stylesheets/jquery.tooltip/jquery.tooltip.css" type="text/css" />
    <script type="text/javascript" src="content_pay/javascripts/jquery.min.js"></script>
    <script type="text/javascript" src="content_pay/javascripts/jquery.tooltip.js"></script>
    <script type="text/javascript">
      $j = jQuery.noConflict();
      $j(document).ready(function(){
        $j("div.item").tooltip();
      });
    </script>
    
    
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.js"></script>
<script type="text/javascript" src="js/jquery.price_format.1.7.min.js"></script>
<link rel="stylesheet" type="text/css" href="admin/css/jsDatePick_ltr.min.css" />
<script type="text/javascript" src="admin/css/jsDatePick.min.1.3.js"></script>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script language="javascript" src="js/cal2.js"></script>
<style type="text/css">
.content_menu_expand{
	position:absolute; 
	right:-5px;
	top:20px;
	z-index:999;
	background-color: #ffffff;
	-moz-border-radius: 7px;
	-webkit-border-radius: 7px;
	color: #000000;
	width:300px; 
	max-height:180px;
	overflow:auto;
}


.passul{padding-left:0; border:1px solid black}
.bgkhac {background: #eee;}
.passul ul{padding:0px}
.passul ul li {color:#474747; font-size:12px;padding: 5px 0;padding-left:5px;list-style: none;}
.passul ul li:hover { background: #0A246A;color:white;text-decoration: none;list-style: none;}


</style>
<style type="text/css">
body{padding:0px; margin:0px}
.table{ width:715px; height:570px; margin:auto; }
table > tr {}
.table td {width:97px; height:50px; text-align:left;  }
.content { width:740px;padding-bottom: 10px;border-radius: 10px; border-radius: 10px; box-shadow:2px 2px 4px; background:#357cb0}
.content p { font-size:12px;left:2px;width:14px}
.ngaytruoc { color:#dbd1c7; }
.ngayhientai { background:#bf2400; border:#006; border-radius: 3px; padding:0px 8px ; color:#FFF}
.ngay { color:#656564;}
.sukien{  padding-top:15px;color:#ab044b;}
.sukien1 {background:#e1fcd0; color:#ab044b;font-size: 11px;}
.chunhat{ color:#c62a00;}
.container{font-family:Arial, Helvetica, sans-serif}
</style>


<div id="contains" style="height:100%;">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_accountant; ?>&rarr;<?=$l_pay_calendar;?></div>
	<div class="content_code" style="height:100%;">
		<div class="approval-right" style="padding-right:10px; height:100%;">

<form action="pay.php" method="post" name="frm1" id="f_ac_elisoft_order_tax" style="padding-left: 4px;">
			<table border="0" class="ftable1" cellspacing="0" style="background: rgb(92, 165, 206);padding: 3px 5px;">
		    	<tr>
		        	<th style="height:30px;width: 70px"><?php echo $l_month;?></th>
		            <th style="height:30px;">
		            	<select onchange="document.frm1.submit()" style="width:50px;height:24px;font-size:12px;text-align:center;valign:middle;" id="months" name="months">
							<?php for($i=1;$i<=12;$i++){?>
								<option value="<?=$i?>"  
									<?php 
										if($month==$i){
											?>
											selected="selected"
											<?php 
										}
									?>
								>
									<?php echo $i?>
								</option>
							<?php }?>
						</select> 
		            </th>
		            <th style="height:30px;width: 70px"><?php echo $l_year;?></th>
		            <th style="height:30px;">
		            	<select onchange="document.frm1.submit()" style="width:60px;height:24px;font-size:12px;text-align:center;valign:middle;" id="years" name="years">
							<?php for($i=2012;$i<=($vyear+7);$i++){?>
								<option value="<?=$i?>"  
									<?php 
										if($year==$i){
											?>
											selected="selected"
											<?php 
										}
									?>
								>
									<?php echo $i?>
								</option>
							<?php }?>
						</select> 
		            </th>
		        </tr>
		    </table>
		    </form>
		    <br>
					<input style="margin:2px 5px 0 0; font-size: 12px;" type="button" value="<?= $l_sendmail ?>" onclick="showsendmailPay()"  class="btn_choose"  />
             <br>
		    <div id="showpay1" style="padding-top: 10px; <?php if($nofullsize==0) echo 'display: none;'; else echo 'display: block;';?>">
			<table style="min-width: 1000px">
			
<tr>
	<td style="vertical-align: top;min-width: 300px;width: 500px">
			<p style="padding-top: 10px;padding-bottom: 5px;">	<?=$l_pay1?></p>
						<table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="width: 500px;margin:auto;">
			<tr align='center'>
				<th style="width:30px;"><?=$l_no?></th>
				<th style="width:190px;"><?=$l_pay_category?></th>
				<th style="width:110px;"><?=$l_pay_time?></th>
				<th style="width:110px;"><?=$l_pay_money?></th>
				<th><?=$l_status?></th>
			</tr>
							
							<?php  
							$k=1;
							foreach ($mang as $value => $giatri){?>
							<tr>
								<td class="tdfirst" style="width:30px;"><?=$k?></td>
								<td class="tdfirst" style="text-align: left;"><?php echo $giatri[1];?></td>
								<td style="width: 100px;" ><input type="text" value="<?php echo $giatri['2'];?>" class="in_testfield" style="width:100px;float:left;height:24px;text-align: right; padding-right: 5px" readonly="readonly" disabled="disabled" /></td>
								<td style="width: 100px;" ><input type="text" value="<?php if($giatri[3]!=0) echo $giatri['3'];?>" class="in_testfield" style="width:100px;float:left;height:24px;text-align: right; padding-right: 5px" readonly="readonly" disabled="disabled" /></td>
								<td>
									<?php if($giatri[4]==0){?>
									<img title="<?=$l_pay_status1?>" src="images/not_yet.png">
									<?php }else{?>
									<img title="<?=$l_pay_status2?>" src="images/check.png">
									<?php }?>
								</td>
							</tr>
							
							<?php 
							$k++;
							}?>
						</table>
		
		<br>
		<p style="padding-top: 10px;padding-bottom: 5px;"><?=$l_pay2?></p>
		<table cellpadding="0" cellspacing="1" border="0" class="ftable1" style="width: 500px;margin:auto;">
			<tr align='center'>
				<th style="width:30px;"><?=$l_no?></th>
				<th style="width:190px;"><?=$l_pay_category?></th>
				<th style="width:110px;"><?=$l_pay_time?></th>
				<th style="width:110px;"><?=$l_pay_money?></th>
				<th><?=$l_status?></th>
			</tr>
							
							<?php  
							$k=1;
							foreach ($mang2 as $value => $giatri){?>
							<tr>
								<td class="tdfirst" style="width:30px;"><?=$k?></td>
								<td class="tdfirst" style="text-align: left;"><?php echo $giatri[1];?></td>
								<td style="width: 100px;" ><input type="text" value="<?php echo $giatri['2'];?>" class="in_testfield" style="width:100px;float:left;height:24px;text-align: right; padding-right: 5px" readonly="readonly" disabled="disabled" /></td>
								<td style="width: 100px;" ><input type="text" value="<?php if($giatri[3]!=0) echo $giatri['3'];?>" class="in_testfield" style="width:100px;float:left;height:24px;text-align: right; padding-right: 5px" readonly="readonly" disabled="disabled" /></td>
								<td>
									<?php if($giatri[4]==0){?>
									<img title="<?=$l_pay_status1?>" src="images/not_yet.png">
									<?php }else{?>
									<img title="<?=$l_pay_status2?>" src="images/check.png">
									<?php }?>
								</td>
							</tr>
							
							<?php 
							$k++;
							}?>
						</table>
	</td>
<td style="min-width: 700px;padding-left: 5px;vertical-align: top;">
<img src="images/hide_left.png" title="Show" onclick="showpay(1)" style="margin: 10px 10px -5px;width: 30px;float: left;cursor: pointer;" />
<div class="container">
  <div class="content">
  <div style="text-align:center; text-transform:uppercase; padding:10px ">
  <a href="pay.php?prev=on&months=<?=$month?>&years=<?=$year?>"><img src="images/left.png" style="margin: 10px 10px -5px;" /></a>
  <span style=" color:#FFF" ><? echo $months[$month-1]." ".$year;?></span>
  <a href="pay.php?next=on&months=<?=$month?>&years=<?=$year?>"><img src="images/right.png" style="margin: 10px 0 -5px 10px;"  /></a>
  </div>
<table class="table" border="2px" bordercolor="#cac6c0" frame="void" cellpadding="0" cellspacing="0" style="border-radius: 10px; background:#FFF;">
	<tr >
	<?php
	$i=1;
	foreach($days as $day){
		if($i==1){
	?>
		<td style="border-top-left-radius:10px; background:#f1e8df; text-align:center;color:#c62a00;text-transform: uppercase;">
		<?php }else if($i==7){?>
		<td style="border-top-right-radius:10px; background:#f1e8df; text-align:center;text-transform: uppercase;">
			<?php }else{?>
		<td style="background:#f1e8df; text-align:center;text-transform: uppercase;">
		<?php }?>
			<div align="center"><b><?echo $day;?></b></div>
		</td>
	<?php 
	$i++;
	}?>
<?php 
for( $count=0;$count<(6*7);$count++){
	$dayarray = getdate($start);
	if((($count) % 7) == 0){
		if($dayarray['mon'] != $month)
		break;
		echo "</tr><tr style='height: 100px;'>";
	}
	if($count < $firstdayarray['wday'] || $dayarray['mon'] != $month){
		//if($count!=0)
			echo "<td></td>";
		//else 
		//	echo "<td bgcolor='#FFCC99' bordercolor='#FFCC99' style='width: 100px;'><br></td>";
	}
	else
	{
	$i=0;
	$sukien="";
	//$sukien.='<p class="sukien">';
	$str='<div class="tooltip_description" style="display:none" title="">';
	foreach ($mang as $value => $giatri){
			$d=$giatri[2];
			$l_method="";
			if($giatri[5]==0)
				$l_method=$l_method0;
			if($giatri[5]==1)
				$l_method=$l_method11;
			if($giatri[5]==2)
				$l_method=$l_method22;
			if($giatri[5]==3)
				$l_method=$l_method33;
			if($giatri[5]==4)
				$l_method=$l_method44;
			if($giatri[5]==5)
				$l_method=$l_method55;
			if($dayarray['mday'] == date('d',strtotime($d))){
				if($i==0)
					$sukien.='<div id="item_2" class="item">
			        <span>'.$l_method.'-'.$giatri[1].'</span><br>';
			     else $sukien.= '<span>'.$l_method.'-'.$giatri[1].'</span><br>';
				if($giatri[3]==0 || $giatri[3]=='')
					$str.='<span>'.$l_method.'-'.$giatri[1].' : '.$l_pay_notinput.'</span><br>';
				else 
			    	$str.='<span>'.$l_method.'-'.$giatri[1].' : '.$giatri[3].'</span><br>';
			  
				//$sukien.= '<span>'; 
				//$sukien.= $giatri[1];
				//$sukien.= '</span><br>';
				$i++;
			}
			
			
			
	}	
	if($i!=0)
	$sukien.=$str.'</div></div>';
	//$sukien.= '</p>';
	if($dayarray['mday'] == $datearray['mday'] && $dayarray['mon'] == $datearray['mon'] && $dayarray['year']== $datearray['year']){	
?>
			<td <?php if($i!=0)echo "class='sukien1'";?>>
			<div style="height: 97px;overflow: auto;">
            	<p class="ngayhientai">
            	
<?php }else{?>
			<td <?php if($i!=0)echo "class='sukien1'";?>>
			<div style="height: 97px;overflow: auto;">
                <p <?php if($dayarray['wday']==0) echo 'class="chunhat"'; else echo 'class="ngay"'; ?> >
                
<?php }
		$str=$dayarray['mday'];
		echo $str;
		echo $sukien;
		
?>
</p>
</div>

			</td>
			
		<?php
		$start += ADAY;
		//}
	}
}
?>
</table>
    </div>
  </div>
</td>
</tr>
</table>
</div>
<div id="showpay2"  style="padding-top:10px;<?php if($nofullsize==0) echo 'display: block;'; else echo 'display: none;';?>">
<img src="images/hide_right.png" title="Hide" onclick="showpay(2)" style="margin: 10px 10px -5px;width: 30px;float: left;cursor: pointer;" />
<div class="container">
  <div class="content" style="width: 100%">
  <div style="text-align:center; text-transform:uppercase; padding:10px ">
  <a href="pay.php?prev=on&months=<?=$month?>&years=<?=$year?>"><img src="images/left.png" style="margin: 10px 10px -5px;" /></a>
  <span style=" color:#FFF" ><? echo $months[$month-1]." ".$year;?></span>
  <a href="pay.php?next=on&months=<?=$month?>&years=<?=$year?>"><img src="images/right.png" style="margin: 10px 0 -5px 10px;"  /></a>
  </div>
<table class="table" border="2px" bordercolor="#cac6c0" frame="void" cellpadding="0" cellspacing="0" style="border-radius: 10px; background:#FFF;width: 98%">
	<tr >
	<?php
	$i=1;
	foreach($days as $day){
		if($i==1){
	?>
		<td style="border-top-left-radius:10px; background:#f1e8df; text-align:center;color:#c62a00;text-transform: uppercase;">
		<?php }else if($i==7){?>
		<td style="border-top-right-radius:10px; background:#f1e8df; text-align:center;text-transform: uppercase;">
			<?php }else{?>
		<td style="background:#f1e8df; text-align:center;text-transform: uppercase;">
		<?php }?>
			<div align="center"><b><?echo $day;?></b></div>
		</td>
	<?php 
	$i++;
	}?>
<?php 
$start= mktime(0,0,0,$month,1,$year);
$firstdayarray = getdate($start);
for( $count=0;$count<(6*7);$count++){
	$dayarray = getdate($start);
	if((($count) % 7) == 0){
		if($dayarray['mon'] != $month)
		break;
		echo "</tr><tr style='height: 130px;'>";
	}
	if($count < $firstdayarray['wday'] || $dayarray['mon'] != $month){
		//if($count!=0)
			echo "<td></td>";
		//else 
		//	echo "<td bgcolor='#FFCC99' bordercolor='#FFCC99' style='width: 100px;'><br></td>";
	}
	else
	{
	$i=0;
	$sukien="";
	//$sukien.='<p class="sukien">';
	$str='<div class="tooltip_description" style="display:none" title="">';
	foreach ($mang as $value => $giatri){
			$d=$giatri[2];
			$l_method="";
			if($giatri[5]==0)
				$l_method=$l_method0;
			if($giatri[5]==1)
				$l_method=$l_method11;
			if($giatri[5]==2)
				$l_method=$l_method22;
			if($giatri[5]==3)
				$l_method=$l_method33;
			if($giatri[5]==4)
				$l_method=$l_method44;
			if($giatri[5]==5)
				$l_method=$l_method55;
				
			if($dayarray['mday'] == date('d',strtotime($d))){
				if($i==0)
					$sukien.='<div id="item_2" class="item">
			        <span>'.$l_method.'-'.$giatri[1].'</span><br>';
			     else $sukien.= '<span>'.$l_method.'-'.$giatri[1].'</span><br>';
				if($giatri[3]==0 || $giatri[3]=='')
					$str.='<span>'.$l_method.'-'.$giatri[1].' : '.$l_pay_notinput.'</span><br>';
				else 
			    	$str.='<span>'.$l_method.'-'.$giatri[1].' : '.$giatri[3].'</span><br>';
			  
				//$sukien.= '<span>'; 
				//$sukien.= $giatri[1];
				//$sukien.= '</span><br>';
				$i++;
			}
			
			
			
	}	
	if($i!=0)
	$sukien.=$str.'</div></div>';
	//$sukien.= '</p>';
	if($dayarray['mday'] == $datearray['mday'] && $dayarray['mon'] == $datearray['mon'] && $dayarray['year']== $datearray['year']){	
?>
			<td <?php if($i!=0)echo "class='sukien1'";?>>
			<div style="height: 97px;overflow: auto;">
            	<p class="ngayhientai">
            	
<?php }else{?>
			<td <?php if($i!=0)echo "class='sukien1'";?>>
			<div style="height: 97px;overflow: auto;">
                <p <?php if($dayarray['wday']==0) echo 'class="chunhat"'; else echo 'class="ngay"'; ?> >
                
<?php }
		$str=$dayarray['mday'];
		echo $str;
		echo $sukien;
		
?>
</p>
</div>

			</td>
			
		<?php
		$start += ADAY;
		//}
	}
}
?>
</table>
    </div>
  </div>
</div>
			<input style="margin:12px 5px 0 0; font-size: 12px;" type="button" onclick="popup_window_show('#sample1', { pos : 'window-center', width : '760px', height:'800px'});" name="all" value="<?=$l_setting?>" class="btn_choose" />
			<?php //if($month==$nmonth){?>
			<input style="margin:12px 5px 0 0; font-size: 12px;" type="button" onclick="popup_window_show('#sample2', { pos : 'window-center', width : '700px', height:'800px'});" name="all" value="<?=$l_input?>" class="btn_choose" />				
			<?php //}?>	
			
			
			
		</div>
		

		
		
	</div>
	
	
</div>
<?php mysql_close($connection);?>